<head th:fragment="headerCss">
    <meta charset="utf-8">
    <title>竞赛管理平台</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta name="keywords" content=""/>
    <meta name="description"
          content="竞赛管理平台"/>
    <link rel="stylesheet" href="/js/layui/css/layui.css">
    <!-- Bootstrap CSS File -->
    <link rel="stylesheet" href="/css/examination/common.css">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link rel="shortcut icon" href="favicon.ico">
    <style>
        .marR10 {
            width: 20px;
            height: 20px;
            display: block;
            float: left;
            margin: 2px 10px 0 0;
        }

        .mar10 {
            width: 750px;
            margin-top: 20px;
            margin-left: auto;
            font-size: 28px;
            padding: 10px 0;
        }

        .mar10:hover {
            background: #efefef;
        }

        label {
            display: block
        }

        a {
            color: #666;
        }

        #layui-layer1 .layui-layer-btn {
            text-align: center;
        }

        #layui-layer1 .layui-layer-btn .layui-layer-btn0 {
            background: #FF6A66;
            color: #fff;
            border: none;
            font-size: 14px;
        }

        #layui-layer1 .layui-layer-btn .layui-layer-btn1 {
            background: white;
            border: 1px solid #FF6A66;
            font-size: 14px;
        }

        #ticketNumber, #idCard, #name {
            color: #000;
        }

        .infoBoxNew {
            background: #fff !important;
            box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -moz-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -webkit-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -ms-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
        }

        .div-1 {
            margin: 50px auto;
            width: 200px;
            margin-left: 300px;
        }

        #examShowtime #lastEndTime {
            margin-left: 0;

        }

        .countdown-num {
            padding: 20px 0 16px 0;
            font-size: 18px;
            color: #000;
        }

        .countdown-num img, .countdown-num span {
            vertical-align: middle;
        }

        .options, .slogan, .topic, .login_panel {
            width: 804px !important;
        }

        .login_panel {
            padding: 0 40px;
        }

        #examShowtime {
            height: 120px;
            line-height: normal;
            background: #fff;
            -webkit-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -moz-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -ms-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            -ms-border-radius: 4px;
            border-radius: 4px;
            margin-left: 0;
            color: #F89500;
            float: none;
            text-align: center;
            width: 396px;
        }

        .right-question {
            width: 372px;
            float: right;
        }

        .sheet {
            margin-left: 0;
            background: #fff;
            margin-top: 16px;
            width: 396px;
            padding: 12px 0 129px 0;
        }

        .rt_content_tt {
            height: 56px;
            line-height: 56px;
            margin-bottom: 0;
        }

        .rt_content_tt h2 {
            line-height: 56px;
            margin-bottom: 0;
        }

        .subjectType::before {
            content: none;
        }

        .subjectType {
            padding: 0 40px;
            background: #E2F4FF;
            height: 56px;
            line-height: 56px;
            border-bottom: none;
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            -ms-border-radius: 4px;
            border-radius: 4px;
        }

        .serial {
            width: 24px;
            height: 24px;
            line-height: 24px;
            background: #5AAEDF;
            border-radius: 2px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            -ms-border-radius: 2px;
            margin-right: 8px;
            margin-top: 1px;
            background: #5AAEDF !important;
        }

        input[type="radio"] + label::before {
            content: " ";
            display: inline-block;
            vertical-align: middle;
            width: 20px;
            margin-right: 20px;
            border-radius: 50%;
            -moz-border-radius: 50%;
            -webkit-border-radius: 50%;
            height: 20px;
            border: 1px solid #5AAEDF;
            box-sizing: border-box;
        }

        input[type="radio"]:checked + label::before {
            background-color: #2A87C3;
            background-clip: content-box;
            border: 1px solid #5AAEDF;
            padding: 0.1rem;
            box-sizing: border-box;
        }

        input[type="radio"] {
            position: absolute;
            clip: rect(0, 0, 0, 0);
        }

        input[type="checkbox"] + label::before {
            content: " ";
            display: inline-block;
            vertical-align: middle;
            width: 20px;
            margin-right: 20px;
            /*border-radius: 50%;*/
            /*-moz-border-radius: 50%;*/
            /*-webkit-border-radius: 50%;*/
            height: 20px;
            border: 1px solid #5AAEDF;
            box-sizing: border-box;
        }

        input[type="checkbox"]:checked + label::before {
            background-color: #2A87C3;
            background-clip: content-box;
            border: 1px solid #5AAEDF;
            padding: 0.1rem;
            box-sizing: border-box;
        }

        input[type="checkbox"] {
            position: absolute;
            clip: rect(0, 0, 0, 0);
        }

        .btn-com {
            width: 120px !important;
            height: 40px !important;
            background: #FE8900;
            border-radius: 2px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            -ms-border-radius: 2px;
        }

        .yellow-btn {
            background: #FE8900 !important;
        }

        .green-btn {
            background: #5FA26A !important;
        }

        .div-1 {
            margin-top: 12px !important;
            margin-bottom: 20px !important;
        }

        #sub {
            background: #5AAEDF !important;
            width: 120px !important;
            height: 40px !important;
            border-radius: 2px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            -ms-border-radius: 2px;
        }

        .answerSheet ul, #choice, #case, #questionsBox {
            padding: 5px 24px 5px 24px;
            text-align: left;
            margin-bottom: 0;
        }

        .state {
            padding: 0 24px;
            width: 100%;
            margin-bottom: 14px;
        }

        .onenape, .rt_content_tt {
            padding: 0 24px;
            width: 100%;
        }

        .onenape {
            font-weight: bold;
            color: #000;
            font-size: 14px;
        }

        .answerSheet li, #choice li, #case li, #questionsBox li {
            width: 24px;
            height: 24px;
            line-height: 22px;
            border-radius: 2px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            -ms-border-radius: 2px;
            font-size: 14px;
            border: 1px solid #DFEAF1;
            color: #333;
        }

        .answerSheet li:hover, #choice li:hover, #case li:hover, #questionsBox li:hover {
            border-color: #5AAEDF;
            background: #5AAEDF;
            color: #fff;
        }

        #questionsBox li:hover a, #case li:hover a {
            color: #fff;
            text-decoration: none;
        }

        .answerSheet .hasBeenAnswer, #choice .hasBeenAnswer, #case .hasBeenAnswer, #questionsBox .hasBeenAnswer {
            background: #5AAEDF;
            border: 1px solid #5AAEDF;
        }

        .answerSheet li a, #choice li, #case li a {
            /*width: 24px;*/
            /*height: 24px;*/
            /*border: 1px solid #DFEAF1;*/
        }

        .done span {
            border-radius: 2px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            -ms-border-radius: 2px;
            background: #5AAEDF;
        }

        .fail span {
            background: none;
            border: 1px solid #DFEAF1;
        }

        .layui-layer-btn0 {
            background: #FF6A66 !important;
            color: #fff !important;
            border: none !important;
            font-size: 14px !important;
        }

        .layui-layer-btn1 {
            background: #fff !important;
            color: #000;
            border: 1px solid #FF6A66 !important;
            font-size: 14px !important;
            border: none !important;
        }

        .layui-layer-btn {
            text-align: center !important;
        }

        .icon-box {
            display: table;
            margin-top: 0px;
        }

        .info {
            display: block;
            clear: both;
        }

        .icon-box img {
            width: 16px;
            height: 16px;
            float: left;
            margin-top: 24px;
            margin-right: 16px;
        }

        .exam-title {
            height: 120px;
            background: #FFFFFF;
            box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -moz-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -webkit-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -ms-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            border-radius: 4px;
            -moz-border-radius: 4px;
            -webkit-border-radius: 4px;
            -ms-border-radius: 4px;
            margin-bottom: 16px;
            clear: both;
            width: 100%;
            padding-left: 16px;
        }

        .options {
            padding: 0;
        }

        .topic {
            background: #fff;
            box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -webkit-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -moz-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -ms-box-shadow: 0px 3px 6px 1px rgba(181, 197, 223, 0.1);
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            -ms-border-radius: 4px;
            border-radius: 4px;

            width: 100%;
            height: calc(100vh - 295px);
        }

        .logo-box {
            float: left;
            margin-top: 36px;
        }

        .jin1 {
            margin-right: 12px;
        }

        .content-text {
            float: left;
            margin-left: 16px;
            width: 70%;
        }

        .content-text .exam-name {
            color: #040404;
            font-size: 20px;
            font-weight: bold;
            margin-top: 42px;
        }

        .content-text .exam-des {
            color: #666666;
            font-size: 12px;
        }

        .ques-num {
            font-weight: normal;
            font-size: 14px;
            color: #666666;
        }

        .content-text .anliClass {
            margin-top: 35px;
        }

        .resourceUrlVideo {
            width: 90%;
        }

        .mar10 {
            width: 100%;
        }

        .resourceUrlImg img, .resourceUrlVideo video {
            width: 100%;
            height: 250px;
            margin: 0 auto;
            display: block;
        }

        .marVideo:hover {
            background: none;
        }

        .layui-layer {
            left: 50% !important;
            top: 50% !important;
            margin-left: -130px !important;
            margin-top: -73px !important;
        }

        .heading {
            margin: 25px auto 5px;
        }
        .alerted .button {
            width: 100%;
            margin: 0 auto;
            text-align: center;
        }
        .alerted .button span {
            margin-right: 0;
        }
        .alerted{
            width: 520px;
            height: 270px;
            padding: 0 0 36px 0;
            background: #fff;
        }
        .alerted .title{
            font-size: 14px !important;
            border: 1px solid #E9E9E9;
            color: #333;
            height: 40px;
            line-height: 40px;
            text-align: left;
            padding: 0 24px;
            background: #F9F9F9;
            display: flex;
            align-items: center;

        }
        .alerted span{
            flex: 1;
        }
        .alerted img{
            width: 16px;
            height: 16px;
            cursor: pointer;
        }
    </style>
</head>
<body class="signin" style="overflow-x: hidden;background: #F3F6FB">

<div class="infoBox infoBoxNew">
    <div class="info">
        <div class="redlogo"><img src="/img/logo10.png"></div>
        <div class="attributes">
            <h1 id="roomNumber"></h1>
            <h1 id="seatNumber"></h1>

            <!--            <div class="icon-box">-->
            <!--                <img src="/img/kao3.png">-->
            <!--                <span  id="idCard"></span>-->
            <!--            </div>-->
            <!--            <div class="icon-box">-->
            <!--                <img src="/img/kao2.png">-->
            <!--                <span   id="ticketNumber"></span>-->
            <!--            </div>-->
            <h1 class="icon-box">
                <!--                <img src="/img/kao1.png">-->
                <span id="name"></span>
            </h1>

            <div>
                <button style="height: 64px;color: #5AAEDF;background: none;" class="btn" id="next" onclick="reload();">
                    <img width="30" src="/img/refresh.png" style="margin-right: 5px"/>刷新
                </button>

                <button style="height: 64px;color: #5AAEDF;background: none;" class="btn" id="full"
                        onclick="maximize();"><img width="30" src="/img/full.png" style="margin-right: 5px"/>全屏
                </button>
            </div>
        </div>
    </div>
</div>


<div class="heading">

    <div class="options">
        <div class="exam-title">
            <div class="logo-box">
                <img src="/img/jin1.png" class="jin1" width="121" height="48">
                <img src="/img/jin2.png" width="48" height="48">
            </div>
            <div class="content-text">
                <div class="exam-name"></div>
            </div>
        </div>
        <div class="topic">
            <div class="subjectType">
                单项选择题
            </div>
            <div class="login_panel" style="margin: auto;font-size:20px;">
                <div id="content"
                     style="margin-top:40px;height:calc(100vh - 500px);border-bottom:1px dashed #ccc;overflow: hidden;overflow-y: auto;">
                </div>

                <div class="adjust" style="margin-top: 48px">
                    <div class="btnBox">
                        <button class="btn first-btn btn-block btn-com not-allowed unify" onClick="first();">第一题
                        </button>
                        <button class="btn yellow-btn btn-block btn-com not-allowed unify gray" onClick="pre();">
                            上一题
                        </button>
                        <button class="btn green-btn btn-block btn-com not-allowed unify green" onClick="next();">
                            下一题
                        </button>
                        <button class="btn last-btn btn-block btn-com unify" onClick="last();">最后一题</button>
                    </div>

                </div>

            </div>
            <div style="background: #F3F6FB;height: 16px;margin-top: 48px"></div>
            <div class="div-1">
                <input class="btn btn-block not-allowed resetSub" id="sub" onclick="question(this);" value="交卷"/>

            </div>
        </div>

    </div>
    <div class="right-question">
        <div class="" id="examShowtime">
            <div class="countdown-num">
                <img src="/img/times.png" width="16" height="16" style="margin-right: 12px">
                <span>考试倒计时</span>
            </div>
            <div id="lastEndTime"></div>
        </div>
        <div class="sheet">
            <div class="rt_content_tt">
                <h2>答题卡</h2>
            </div>
            <div class="state"><p class="done"><span></span>已做</p>
                <p class="done fail"><span></span>未做</p></div>
            <p class="onenape">
                单项选择题
                <span class="ques-num">（共<span class="answer-num"></span>小题）</span>
            </p>
            <div class="rt_content_nr answerSheet">
                <ul id="answer"></ul>
            </div>
            <p class="onenape">
                多项选择题
                <span class="ques-num">（共<span class="choice-num"></span>小题）</span>
            </p>
            <ul id="choice"></ul>
            <p class="onenape">
                判断题
                <span class="ques-num">（共<span class="questionsBox-num"></span>小题）</span>
            </p>
            <ul id="questionsBox"></ul>
            <p class="onenape anlifenxi">
                案例分析题
                <span class="ques-num">（共<span class="case-num"></span>小题）</span>
            </p>
            <ul id="case"></ul>
        </div>
    </div>

</div>


</div>

<!--<div class="alerted">-->
<!--    <p class="query">检查是否有漏题，再确认交卷！</p>-->
<!--    <div class="button">-->
<!--        <span onclick="submitDate()">坚持提交</span>-->
<!--        <span onclick="continuest()">继续考试</span>-->
<!--    </div>-->
<!--</div>-->

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
<script src="/js/layui/layui.js"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"
        th:src="@{/js/plugins/validate/jquery.validate.min.js}"></script>
<script src="/js/plugins/validate/messages_zh.min.js" th:src="@{/js/plugins/validate/messages_zh.min.js}"></script>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script type="text/javascript">

    function resizeWindow(event) {
        let e = event || window.event;
        e.preventDefault();
        if (e) {
            e.returnValue = '';
            return false;
        }
    }

    window.addEventListener('beforeunload', resizeWindow, false);


    //f5、f12、f11禁用
    document.onkeydown = function (e) {
        var ev = window.event || e;
        var code = ev.keyCode || ev.which;

        if (code == 123) { //屏蔽f12
            if (ev.preventDefault) {
                ev.preventDefault();
            } else {
                ev.keyCode = 0;
                ev.returnValue = false;
            }
        }

        // if ((window.event.altKey) &&
        if (((window.event.keyCode == 37) || //屏蔽Alt+方向键←
            (window.event.keyCode == 39))) { //屏蔽Alt+方向键→
            event.returnValue = false;
        }
        // if ((event.keyCode == 8) || //屏蔽退格删除键
        if (
            (event.keyCode == 116) || //屏蔽F5刷新键
            (event.ctrlKey && event.keyCode == 82)) { //Ctrl+R
            event.keyCode = 0;
            event.returnValue = false;
        }
        if (event.keyCode == 27) {
            event.keyCode = 0;
            event.returnValue = false;
        }
        if (event.keyCode == 122) {
            event.keyCode = 0;
            event.returnValue = false;
        } //屏蔽F11
        if (event.ctrlKey && event.keyCode == 78) event.returnValue = false; //屏蔽Ctrl+n
        if (event.shiftKey && event.keyCode == 121) event.returnValue = false; //屏蔽shift+F10
        if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
            window.event.returnValue = false; //屏蔽shift加鼠标左键新开一网页
        if ((window.event.altKey) && (window.event.keyCode == 115)) { //屏蔽Alt+F4
            window.showModelessDialog("about:blank", "", "dialogWidth:1px;dialogheight:1px");
            return false;
        }
    };

    var exam = JSON.parse(window.localStorage.getItem("exam.html"));
    var info = JSON.parse(window.localStorage.getItem("info"));
    var dates = JSON.parse(window.localStorage.getItem("dates"));
    var intro = JSON.parse(window.localStorage.getItem("intro"));
    var dates1 = dates * 60;
    let newEndTime = intro.endTime;
    let newStartTime = info.nowDate


    var allowNum = info.allowNum; // 允许三次切屏，超过则提交
    window.onblur = function () {
        var el = document.documentElement;
        // 这里的 el 可以是其他的页面元素，这样实现的就是这个元素的全屏，而不是整个页面的全屏
        //fullScreen(el);
        if (allowNum < 1) {
            // submit()
        }
        allowNum--;
        // layer.confirm("你已切屏，注意切屏次数过多将会强制交卷！！！", {
        //     btn: ['确定', '取消']
        // });
    };

    function maximize() {
        var el = document.documentElement;
        fullScreen(el);
    }

    function fullScreen(el) {
        var rfs = el.requestFullScreen || el.webkitRequestFullScreen ||

            el.mozRequestFullScreen || el.msRequestFullScreen;

        if (typeof rfs != "undefined" && rfs) {

            rfs.call(el);

        } else if (typeof window.ActiveXObject != "undefined") {

            //for IE，这里其实就是模拟了按下键盘的F11，使浏览器全屏

            var wscript = new ActiveXObject("WScript.Shell");

            if (wscript != null) {

                wscript.SendKeys("{F11}");

            }

        }
    }

    function boxShow() {
        const answerList = JSON.parse(window.localStorage.getItem("answerList"));
        const emptyValues = answerList ? answerList.filter(item => item.value === '') : [];

        if (!answerList || emptyValues.length > 0) {
            topicSubmit(emptyValues.length);
        } else {
            layer.open({
                title: '提示',
                btn: ['确认'],
                moveOut: true,
                zIndex: 999999,
                content: '是否确定交卷？',
                yes: function (index, layero) {
                    submit();
                }
            });
        }
    }

    function topicSubmit(emptyCount = 0) {
        // 如果为空，默认取 `exam.questions` 的长度
        const remainingQuestions = emptyCount || (exam && exam.questions ? exam.questions.length : 0);

        const dome = `
        <p class="query" style="margin: 20px">
            您还有<span class="questionNum">${remainingQuestions}</span>题未答完，是否确定交卷？
            <br>
            如果确定交卷，请输入二次加密号进行再次确认
        </p>
        <input type="text" id="num2" class="ti4 layui-input" placeholder="请输入二次加密号" autocomplete="new-password">
    `;

        layer.open({
            title: '提示',
            btn: ['确认'],
            area: ['450px', '300px'],
            zIndex: 999999,
            content: dome,
            move: '.layui-layer-title', // 开启拖拽，限制在标题栏
            yes: function (index, layero) {
                const num2Value = $('#num2').val().trim();

                // 检查二次加密号
                if (!num2Value) {
                    layer.msg('请输入二次加密号！', { icon: 2 });
                    return;
                }

                if (num2Value === info.num2) {
                    submit();
                    layer.close(index); // 关闭弹窗
                } else {
                    layer.msg('二次加密号不正确', { icon: 2 });
                }
            },
            success: function (layero) {
                // 增强拖拽体验
                layero.find('.layui-layer-title').css('cursor', 'move');
            }
        });
    }


    //单选 多选 切换
    $(".tap").find('dd').click(function () {
        let idx;
        $(this).addClass('active').siblings().removeClass('active');
        if ($(this).attr('data-type') == '1') {
            $(".subjectType").text('单项选择题');
            idx = $("#answer").find('li').eq(0).attr('data-index');
            index = idx;
            changeCss(idx)
        } else {
            $(".subjectType").text('多项选择题');
            idx = $("#choice").find('li').eq(0).attr('data-index');
            index = idx;
            if (idx > 0) {
                $(".gray").css('background', '#43BD00').attr('disabled', false);
            }
            changeCss(idx)
        }
    })

    $('#sub').attr("title", "考试时间大于" + dates + "分钟才能交卷！");

    //题目总数
    var allsubject = '';
    var index = 0;
    var oneReload=false
    $(function () {
        const doSomething = async () => {
            document.querySelector("#lastEndTime").innerHTML = ''
            console.log('开始获取')
            await reload()
            // $("#roomNumber").html("考场号：" + info.roomNumber);
            // $("#seatNumber").html("座位号：" + info.seatNumber);
            // $("#name").html("姓名：" + info.name);
            $("#name").html("二次加密：" + info.num2);
            // $("#idCard").html("考生编号：" + info.idCard);
            // $("#ticketNumber").html("准考证号：" + info.ticketNumber);
            //$("#photo").attr("src", info.photo);
            $("#stuSignId").val(info.stuSignId);
            $("#epaperId").val(exam.id);

            $('.exam-name').html(intro.name)
            $('.allQuestion').html(exam.questions.length)
            let allscore = 0;
            exam.questions.forEach(function (value, index, obj) {
                allscore += Number(value.score)
            });
            $('#allscore').html(allscore)
            $("#examTime").html(intro.duration);

            //倒计时
            $.ajax({
                type: "POST",
                url: "/jzApi/examinations/getNowDateTime",
                data: {},
                success: function (r) {
                    //console.log("map =" , r.data.endTime);
                    window.localStorage.setItem("nowDate", r);
                    const _repeatFunction=()=> {
                        // 要重复执行的代码
                        console.log('执行代码...',oneReload);
                        // 重置累计时间
                        if(oneReload){
                            countDown();
                        }else{
                            setTimeout(_repeatFunction, 100);
                        }
                    }
                    _repeatFunction()
                }
            });


            function addZero(i) {
                return i < 10 ? "0" + i : i + "";
            }

            newTime()

            function newTime() {
                $.ajax({
                    type: "POST",
                    url: "/jzApi/examinations/getStartTimeById",
                    data: {
                        id: info.cbatchId
                    },
                    success: function (r) {
                        //console.log("map =" , r.data.endTime);
                        if (r.code == 0) {
                            newEndTime = r.data.endTime
                            newStartTime = r.data.startTime
                            window.localStorage.setItem("startTime", newStartTime);
                            window.localStorage.setItem("endTime", newEndTime);
                        } else {
                            layer.msg(r.msg)
                        }
                    }
                });
            }

            function generateRandomNumber(min, max) {
                return Math.floor(Math.random() * (max - min + 1)) + min;
            }

            var elapsedTime = parseInt(localStorage.getItem("elapsedTime")) || 0; // 从 localStorage 获取已过去的时间
            var set;

            function countDown() {
                // 获取后端传过来的固定开始时间和结束时间
                const startTime = new Date(window.localStorage.getItem("startTime").replace(/-/g, "/"));
                const endTime = new Date(window.localStorage.getItem("endTime").replace(/-/g, "/"));

                // 动态计算当前时间
                const nowTime = new Date(startTime.getTime() + elapsedTime * 1000);
                window.localStorage.setItem("nowDate", nowTime);

                const info = JSON.parse(window.localStorage.getItem("info"));
                const leftTime = parseInt((endTime.getTime() - nowTime.getTime()) / 1000); // 计算剩余时间

                const h = addZero(parseInt(leftTime / (60 * 60) % 24));
                const m = addZero(parseInt(leftTime / 60 % 60));
                const s = addZero(parseInt(leftTime % 60));

                // 更新倒计时时间显示
                document.querySelector("#lastEndTime").innerHTML = `${h} : ${m} : ${s}`;

                // 逻辑判断部分
                if (info.name.indexOf("jzwy") !== -1 || leftTime <= dates1) {
                    $("#sub").attr("disabled", false);
                    $("#sub").removeClass("not-allowed");
                }

                // 倒计时结束逻辑
                if (leftTime < 0) {
                    submit();
                    clearTimeout(set); // 停止倒计时
                    return;
                }

                // 递归调用倒计时，并更新累计时间
                elapsedTime += 1; // 每秒递增
                localStorage.setItem("elapsedTime", elapsedTime); // 将累计时间保存到 localStorage
                set = setTimeout(countDown, 1000);
            }

            // function countDown() {
            //     // let time = await newTime();
            //     var nowTime = new Date();
            //     var endTime = new Date(newEndTime);
            //     console.log(newStartTime,'ssss')
            //     window.localStorage.setItem("nowDate", new Date(nowTime.getTime() + 1000));
            //     var info = JSON.parse(window.localStorage.getItem("info"));
            //     if (window.localStorage.getItem("endTime") != undefined) {
            //          endTime = new Date(window.localStorage.getItem("endTime").replace(/-/g, "/"));
            //     }
            //
            //     var leftTime = parseInt((endTime.getTime() - nowTime.getTime()) / 1000);
            //     // var d = parseInt(lefTtime / (24*60*60))
            //     var h = parseInt(leftTime / (60 * 60) % 24);
            //     var m = parseInt(leftTime / 60 % 60);
            //     var s = parseInt(leftTime % 60);
            //     // d = addZero(d)
            //     h = addZero(h);
            //     m = addZero(m);
            //     s = addZero(s);
            //
            //     if (m % randomNumber == 0) {
            //         newTime();
            //         randomNumber = generateRandomNumber(5, 10);
            //     }
            //
            //     document.querySelector("#lastEndTime").innerHTML = h + ' : ' + m + ' : ' + s;
            //
            //     if (info.name.indexOf("jzwy") != -1 || leftTime <= dates1) {
            //         $("#sub").attr("disabled", false);
            //         $("#sub").removeClass("not-allowed");
            //     }
            //
            //     set = setTimeout(countDown, 1000);
            //     if (leftTime < 0) {
            //         submit();
            //         clearInterval(set);
            //         return
            //     }
            //
            // }

            getData(0);
            //渲染答题卡选中状态
            $('.mar10').click(function () {
                var that = $(this);
                var examId = that.parents('.titleEaxm').attr('data-id');
                var type = that.parents('.titleEaxm').attr('type');
                /*根据题目ID找到对应答题卡*/
                var cardLi = $('li[data-id=' + examId + ']');
                //多选题
                if (type == 1) {
                    var a = true;//控制答题卡是否选中
                    var b = false;//判断选项是否选中
                    if (!that.find("input").prop('checked')) {
                        that.siblings(".mar10").each(function () {
                            //选择了一个选项则为true
                            if ($(this).find("input").prop('checked')) {
                                b = true
                            }
                        });
                    } else {
                        b = true;
                    }
                    if (a) {
                        if (b) {
                            cardLi.addClass('hasBeenAnswer');
                        } else {

                            cardLi.removeClass('hasBeenAnswer');
                        }
                    } else {
                        cardLi.removeClass('hasBeenAnswer');
                    }
                } else if (type != 4) {
                    var a = true;//控制答题卡是否选中
                    var b = false;//判断选项是否选中
                    if (!that.find("input").prop('checked')) {
                        that.siblings(".mar10").each(function () {
                            //选择了一个选项则为true
                            if ($(this).find("input").prop('checked')) {
                                b = true
                            }
                        });
                    } else {
                        b = true;
                    }
                    if (a) {
                        if (b) {
                            cardLi.addClass('hasBeenAnswer');
                        } else {

                            cardLi.removeClass('hasBeenAnswer');
                        }
                    } else {
                        cardLi.removeClass('hasBeenAnswer');
                    }
                    // if (!cardLi.hasClass('hasBeenAnswer')) {
                    //     // that.find("input[type='radio']").prop('checked', true);
                    //     cardLi.addClass('hasBeenAnswer');
                    // }
                }

                $(this).find('textarea').change(function (e) {
                    if (e.target.value) {
                        if (type == 4) {
                            if (!cardLi.hasClass('hasBeenAnswer')) {

                                cardLi.addClass('hasBeenAnswer');
                            }
                        }
                    } else {
                        cardLi.removeClass('hasBeenAnswer');
                    }
                })


            });
            //
            //点击答题卡跳转题目
            $('.anLi').click(function () {
                // var examId = $(this).attr('data-id');
                // /*选中题目ID*/
                // var cardLi = $('div[data-id=' + examId + ']');
                // /*根据题目ID找到对应答题卡*/
                // cardLi.addClass('contentBoxShow');
                // cardLi.removeClass('contentBoxHide');
                // cardLi.siblings().addClass('contentBoxHide');
                // cardLi.siblings().removeClass('contentBoxShow');

                if ($(this).attr('data-type') == 1) {
                    $(".subjectType").text('多项选择题');
                    $(".tap").find('dd').eq(1).addClass('active').siblings().removeClass('active');
                } else {
                    $(".subjectType").text('单项选择题');
                    $(".tap").find('dd').eq(0).addClass('active').siblings().removeClass('active');
                }

                if ($(this).attr('data-type') == 4) {
                    $(".subjectType").text('案例分析题部分');
                }

                if ($(this).attr('data-type') == 2) {
                    $(".subjectType").text('判断题');
                }

                index = $(this).attr('data-index');

                if (index >= exam.questions.length - 1) {
                    $(".green").css('background', '#ccc').attr('disabled', true);
                } else {
                    $(".green").css('background', '#43BD00').attr('disabled', false);
                }

                if (index <= 0) {
                    $(".gray").css('background', '#ccc').attr('disabled', true);
                } else {
                    $(".gray").css('background', '#43BD00').attr('disabled', false);
                }

                toGo(index)
            });
            //答案存入缓存
            $("input").change(function () {
                console.log('--------------')
                var answerList = [];
                var subject = '';
                $('.titleEaxm').each(function (i, res) {
                    var that = $(this);
                    var che = '';
                    var type = that.find("input").attr("type");
                    //单选、判断
                    if (type == 'radio') {
                        var rad = '';
                        if (that.find($('input:checked')).val() != '' && that.find($('input:checked')).val() != undefined) {
                            rad = that.find($('input:checked')).val().substring(0, 1)
                        }
                        answerList.push({id: that.attr("data-id"), value: rad, type: that.attr('type')});
                    } else if (type == 'checkbox') { //多选
                        that.find('input:checkbox:checked').each(function (i) {
                            if ($(this).val() != '') {
                                che += $(this).val().substring(0, 1) + ';;'
                            }
                            // che.push($(this).val());
                        });
                        answerList.push({id: that.attr("data-id"), value: che, type: that.attr('type')});
                    }
                    //进度显示
                    if (that.find($('input:checked')).val() != undefined) {
                        subject = subject * 1 + 1
                    }
                });
                //题目完成进度
                var process = (subject / allsubject) * 100;
                $("#process").html("共" + allsubject + "道题目，已完成" + process.toFixed(2) + "%");

                window.localStorage.setItem("answerList", JSON.stringify(answerList));
                //console.log("answerList",answerList)
                //未完成题目数量
                window.localStorage.setItem("incomplete", allsubject - subject);
            });
            //从缓存取出答案、遍历到页面
            var answerList = window.localStorage.getItem("answerList");
            if (null != answerList) {
                var subject = '';
                var answerListJSON = JSON.parse(answerList);
                //遍历题目
                $('.titleEaxm').each(function () {
                    var that = $(this);
                    for (var i = 0; i < answerListJSON.length; i++) {
                        //根据id找到对应题目
                        if (that.attr("data-id") == answerListJSON[i].id) {
                            if (answerListJSON[i].value != '') {
                                $('li[data-id=' + answerListJSON[i].id + ']').addClass('hasBeenAnswer');
                            }
                            //判断是否多选
                            if (answerListJSON[i].value.indexOf(";;") != -1) {
                                //遍历多选题答案
                                var valueList = answerListJSON[i].value.split(";;");
                                //遍历选项
                                that.find("input").each(function () {
                                    for (var j = 0; j < valueList.length; j++) {
                                        //根据答案找到选项，并渲染选中效果到页面
                                        if ($(this).val().substring(0, 1) == valueList[j]) {
                                            $(this).attr("checked", "checked");
                                        }
                                    }
                                });
                            } else {
                                that.find("input").each(function () {
                                    //根据答案找到选项，并渲染选中效果到页面
                                    if ($(this).val().substring(0, 1) == answerListJSON[i].value) {
                                        $(this).attr("checked", "checked");
                                    }
                                });
                            }
                            break;
                        }
                    }
                    //进度显示
                    if (that.find($('input:checked')).val() != undefined) {
                        subject = subject * 1 + 1
                    }
                });
                //题目完成进度
                var process = (subject / allsubject) * 100;
                //未完成题目数量
                window.localStorage.setItem("incomplete", allsubject - subject);
                $("#process").html("共" + allsubject + "道题目，已完成" + process.toFixed(2) + "%");
            } else {
                window.localStorage.setItem("incomplete", allsubject);
            }

            $("textarea").change(function () {
                let textBox = []
                $('.titleEaxm').each(function (i, res) {
                    var that = $(this);
                    var che = '';
                    var type = that.find("textarea").attr("type");
                    //文本框
                    if (type == 'text') {
                        if (that.find($('textarea')).val() != '' && that.find($('textarea')).val() != undefined) {
                            textBox.push({
                                id: that.attr("data-id"),
                                value: that.find($('textarea')).val(),
                                type: that.attr('type')
                            });
                        }
                    }
                });
                window.localStorage.setItem("textBox", JSON.stringify(textBox));
            });

            //从缓存取出答案、遍历到页面
            var textBox = window.localStorage.getItem("textBox");
            if (null != textBox) {
                var subject = '';
                var textBoxJSON = JSON.parse(textBox);
                //遍历题目
                $('.titleEaxm').each(function () {
                    var that = $(this);
                    for (var i = 0; i < textBoxJSON.length; i++) {
                        //根据id找到对应题目
                        if (that.attr("data-id") == textBoxJSON[i].id) {
                            if (textBoxJSON[i].value != '') {
                                $('li[data-id=' + textBoxJSON[i].id + ']').addClass('hasBeenAnswer');
                            }
                            // //判断空值
                            if (textBoxJSON[i].value != '' && that.find($('textarea')).val() != undefined) {
                                //遍历多选题答案
                                var valueList = textBoxJSON[i].value;
                                $(this).find('textarea').val(valueList)
                                break;
                            }
                        }
                        //进度显示
                        if (that.find($('input:checked')).val() != undefined) {
                            subject = subject * 1 + 1
                        }
                    }
                    //题目完成进度
                    var process = (subject / allsubject) * 100;
                    //未完成题目数量
                    window.localStorage.setItem("incomplete", allsubject - subject);
                    $("#process").html("共" + allsubject + "道题目，已完成" + process.toFixed(2) + "%");
                })
            } else {
                window.localStorage.setItem("incomplete", allsubject);
            }

        }
        doSomething()
    });


    function submitDate() {
        submit();
    }

    function continuest() {
        $(".alerted").hide();
    }

    function question() {

        var intro = JSON.parse(localStorage.getItem("intro"));
        // 考试开始时间 加半个小时
        var startTime = new Date(intro.startTime).getTime() + (60 * 30 * 1000);
        //当前时间
        var thisTime = new Date();
        //考试结束时间
        var endTime = new Date(intro.endTime).getTime();

        let isTrue = JSON.parse(localStorage.getItem('isTrue'));
        let tBox = [];
        let titleEaxms, is = true;

        if (isTrue) {

            $('.titleEaxm').each(function (i, res) {
                $(res).find('input').each(function (k, v) {
                    if ($(v).prop('checked')) {
                        titleEaxms = true;
                        return false;
                    } else {
                        titleEaxms = false;
                    }
                });

                tBox.push({id: $(res).attr('data-id'), value: titleEaxms, type: $(res).attr("type")});

            })
            tBox.forEach(function (val) {
                if (!val.value) {
                    boxShow()
                    is = false;
                }
            })
            if (is) {
                boxShow()
            }

        } else {
            if (thisTime > startTime) {

                $('.titleEaxm').each(function (i, res) {
                    $(res).find('input').each(function (k, v) {
                        if ($(v).prop('checked')) {
                            titleEaxms = true;
                            return false;
                        } else {
                            titleEaxms = false;
                        }
                    });

                    tBox.push({id: $(res).attr('data-id'), value: titleEaxms, type: $(res).attr("type")});

                })
                tBox.forEach(function (val) {
                    if (!val.value) {
                        boxShow()
                        is = false;
                    }
                })
                if (is) {
                    boxShow()
                }

            } else if (endTime - thisTime <= (60 * 30 * 1000)) {

                $('.titleEaxm').each(function (i, res) {
                    $(res).find('input').each(function (k, v) {
                        if ($(v).prop('checked')) {
                            titleEaxms = true;
                            return false;
                        } else {
                            titleEaxms = false;
                        }
                    });

                    tBox.push({id: $(res).attr('data-id'), value: titleEaxms, type: $(res).attr("type")});

                })
                tBox.forEach(function (val) {
                    if (!val.value) {
                        boxShow()
                        is = false;
                    }
                })
                if (is) {
                    boxShow()
                }

            } else {
                boxShow()
                // layer.confirm("考试还未满30分钟,不能交卷",{
                //     btn: ['确定']
                // })
            }
        }

    }

    //获取题目数据
    function getData(titleNumber) {
        var a = '<div>';//题目
        var c = '';//切换按钮
        var an = [];//单选答题卡
        var am = [];//多选答题卡
        var as = [];//案例分析答题卡
        var ab = [];//判断题
        allsubject = exam.questions.length;
        $("#process").html("共" + allsubject + "道题目，已完成0%");
        var arr = exam.questions;
        var t;
        for (var i = 0; i < arr.length; i++) {
            var rand = parseInt(Math.random() * arr.length);
            t = arr[rand];
            arr[rand] = arr[i];
            arr[i] = t;
        }
        //console.log("arr",arr);
        arr.forEach(function (item, index, arr) {
            //渲染答题卡
            if (item.type == 1) {
                am.push(item)
                // am += '<li class="anLi"  data-index="' + index + '" data-id="' + item.id + '"><a href="#">' + (parseInt(index)+1) + '</a></li>';
            } else if (item.type == 4) {
                as.push(item)
            } else if (item.type == 2) {
                ab.push(item)
                // an += '<li class="anLi"  data-index="' + index + '" data-id="' + item.id + '"><a href="#">' + (parseInt(index)+1) + '</a></li>';
            } else {
                an.push(item)
            }
        })
        var convan = [];
        convan = an.concat(am, ab);
        convan.forEach(function (item, index, arr) {
            //控制题目展示
            if (titleNumber == index) {
                f = 'contentBoxShow box'
            } else {
                f = 'contentBoxHide box'
            }
            var list = item.options.split(";;");
            //     var pre = index-1;
            //     var next = index+1;
            var last = arr.length - 1;
            var b = '', d = '', e = '';

            //判断题目类型，写入题目描述
            if (item.type == 0) {  //单选
                if (item.resourceType == 0) {

                    //写入题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="radio" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '" value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（单选题）&nbsp;' + item.introduce + "</span>" + '</div>' + b;

                } else if (item.resourceType == 1) {
                    //写入图片题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="radio" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '" value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（单选题）&nbsp;' + item.introduce + "</span>" + '<img style="width: 500px;height: auto;" src="' + item.resourceUrl + '">' + '</img>' + '</div>' + b;


                } else if (item.resourceType == 2) {
                    //写入题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="radio" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '" value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（单选题）&nbsp;' + item.introduce + "</span>" + '</div>' + b;

                }
            }
            //判断题目类型，写入题目描述
            if (item.type == 2) { //判断
                if (item.resourceType == 0) {
                    //写入题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="radio" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '"  value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（判断题）&nbsp;' + item.introduce + "</span>" + '</div>' + b;

                } else if (item.resourceType == 1) {
                    //写入题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="radio" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '"  value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（判断题）&nbsp;' + item.introduce + "</span>" + '<img style="width: 500px;height: auto;" src="' + item.resourceUrl + '">' + '</img>' + '</div>' + b;

                }


            }
            if (item.type == 1) {  //多选
                if (item.resourceType == 0) {
                    //写入题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="checkbox" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '" value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '"  data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（多选题）&nbsp;' + item.introduce + "</span>" + '</div>' + b;


                } else if (item.resourceType == 1) {
                    //写入题目选项
                    for (var i = 0; i < list.length; i++) {
                        b += '<div class="mar10"><input type="checkbox" class="marR10 subject" id="' + item.id + '_' + i + '" name="' + item.id + '" value="' + list[i] + '" />'
                            + '<label for="' + item.id + '_' + i + '">' + list[i] + '</label></div>'
                    }
                    a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '"  data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index) + 1) + "</span>" + "<span class='bold'>" + '（多选题）&nbsp;&nbsp;' + item.introduce + "</span>" + '<img style="width: 500px;height: auto;" src="' + item.resourceUrl + '">' + '</img>' + '</div>' + b;

                }

            }

            //当前题目为第一题则不能点击上一题，为最后一题不能点击下一题
            if (index == 0) {
                d = '<button class="btn btn-block not-allowed" disabled onclick="pre();">上一题</button>'
            } else {
                d = '<button class="btn btn-block" id="pre" onclick="pre();">上一题</button>'
            }
            if (index == last) {
                e = '<button class="btn btn-block not-allowed" disabled onclick="next();">下一题</button>'
            } else {
                e = '<button class="btn btn-block" id="next" onclick="next();">下一题</button>'
            }
            c = '<div class="div-1 changeBtn" style="display:flex;justify-content:space-between;margin:40px 0 100px 0">' +
                '<button class="btn btn-block" onclick="first();">第一题</button>' +
                d +
                e +
                '<button class="btn btn-block" onclick="last();">最后一题</button></div>';
            a += c;
            a += '</div>';
            // }
        });

        let bs = '', bstr = '';
        as.forEach(function (item, index, arr) {
            //案例分析应用题
            if (item.type == 4) { //案例应用题

                if (item.resourceType == 2) {
                    bs += `<div class="mar10 marVideo">
                            <div class="resourceUrlVideo">
                                <video preload="auto" src="${item.resourceUrl}" controls></video>
<!--<video preload="auto" src="https://jinzhiweiye.oss-cn-hangzhou.aliyuncs.com/2023/11/1103/fengcai.mp4" controls></video>-->

                                <p style="background: #F3F6FB;text-align: center;margin-top: 20px;font-size: 20px;padding: 10px 0;">请选手在纸质答题卷上作答</p>
                            </div>
<!--                            <textarea type="text" placeholder="请输入您的回答,2000字以内" class="subject" style=" visibility: hidden;position: absolute;z-index: -1; margin-top: 10px;border:1px solid #ccc;width:90%;height:140px;line-height: 20px;font-size: 16px;padding: 10px;border-radius:5px" id="${item.id}_${i}" name="${item.id}" ></textarea>-->
<!--                                <div id="content_sn" class="brandCharacteristics editor" id="${item.id}_${i}" name="${item.id}"></div>-->
<!--                             <div id="btnUpload" style="float:left;text-align: center;margin-top: 20px;margin-left: 30px;">-->
<!--                                <img style="background: #fdfdef;border: 1px solid #f5efd8;width: 150px;height: 150px" src="/img/updatass.png">-->
<!--                                <p style="font-size: 14px;margin-top: 10px;font-weight: bold;font-size: 18px">点击上传</p>-->
<!--                                <input type="text" style="opacity:0;width: 1px;" id="fileRoute"-->
<!--                                       name="fileRoute"/>-->
<!--                                <span style="font-size: 14px;width: 100px;height: 100px" id="test" name="test"></span>-->
<!--                                <div style="margin-top: 15px;display: none" class="layui-progress layui-progress-big progress-me" lay-showpercent="true" lay-filter="demo">-->
<!--                                    <div class="layui-progress-bar layui-bg-red" lay-percent="0%"></div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div id="btnUploadimg" style="float:left;text-align: center;margin-left: 30px;display: none;margin-top: 20px">-->
<!--                                <img src="/img/sssppt.png" style="background: #fdfdef;border: 1px solid #f5efd8;width: 150px;height: 150px">-->
<!--                                <p class="btnUploadimgtext" style="font-size: 17px;width:150px;margin-top: 10px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"></p>-->
<!--                            </div>-->
                        </div>`;
                }

                bstr += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + (convan.length + index) + '"><div>' + "<span class='serial'>" + (parseInt((convan.length)) + 1) + "</span>" + "<span class='bold'>" + '（案例分析题）&nbsp;' + item.introduce + "</span>" + '</div>' + bs;

                // else if (item.resourceType == 1) {
                //     //写入题目选项
                //     for (var i = 0; i < list.length; i++) {
                //         b += '<div class="mar10"><input type="text" class="subject" id="' + item.id + '_' + i + '" name="' + item.id + '"  value="" />'
                //             + '</div>'
                //     }
                //     a += '<div type="' + item.type + '" class="' + f + ' titleEaxm" data-id="' + item.id + '" data-index="' + index + '"><div>' + "<span class='serial'>" + (parseInt(index)+1) + "</span>" + "<span class='bold'>" +'（案例分析题）（' + item.score + '分）&nbsp;' + item.introduce+ "</span>" + '<img style="width: 500px;height: auto;" src="'+item.resourceUrl+'">' +'</img>'+  '</div>' + b;
                //
                // }
            }

        })

        a += bstr;

        $("#content").html(a);

        layui.use(['upload', 'element'], function () {
            var upload = layui.upload;
            var element = layui.element;
            upload.render({
                elem: '#btnUpload',
                url: '/common/sysFile/upload',
                // timeout: 36000000,
                // size: 1024 * 100,
                accept: 'file',
                // exts: 'docx|doc|xlsx|pdf|ppt',
                choose: function (obj) {
                    $('.progress-me').show()
                    var files = obj.pushFile();
                    var data = files
                    var values = Object.values(data);
                    for (let i = 0; i < values.length; i++) {
                        name = values[i].name
                    }
                    var keys = Object.keys(obj.pushFile());
                    var lastKey = keys[keys.length - 1];
                    for (const valuesKey in obj.pushFile()) {
                        if (valuesKey !== lastKey) {
                            delete obj.pushFile()[valuesKey];
                        }
                    }
                },
                progress: function (n, elem, e) { // 上传进度回调
                    if (n == 99 || n == 100) {
                        element.progress('demo', `${99}%`)
                    } else {
                        element.progress('demo', `${n}%`)
                    }
                },
                done: function (r) {
                    $("#case").find('li').addClass('hasBeenAnswer')
                    if (r.code == "500") {
                        layer.msg(r.msg);
                        return
                    }
                    if (r.code === '200') {
                        element.progress('demo', `${100}%`)
                    }
                    $("#btnUploadimg").show()
                    $(".btnUploadimgtext").attr('title', r.data)
                    $(".btnUploadimgtext").html(name);
                    $('.progress-me').hide()
                    element.progress('demo', `${0}%`)
                },
                error: function (r) {
                    layer.msg(r.msg);
                    $('.progress-me').hide()
                    element.progress('demo', `${0}%`)
                }
            });

        });

        var str = '';
        an.map(function (item, index) {
            str += '<li class="anLi"  data-type=" ' + item.type + '" data-index="' + index + '" data-id="' + item.id + '"><a href="#">' + (parseInt(index) + 1) + '</a></li>';
        })

        $("#answer").html(str)  //答题卡
        $('.answer-num').html($("#answer").find('li').length)
        str = '';
        am.map(function (item, index) {
            str += '<li class="anLi" data-type=" ' + item.type + '"  data-index="' + (parseInt(an.length + index)) + '" data-id="' + item.id + '"><a href="#">' + (parseInt(an.length + index) + 1) + '</a></li>';
        })

        $("#choice").html(str)  //答题卡
        $('.choice-num').html($("#choice").find('li').length)
        str = '';
        as.map(function (item, index) {
            str += '<li class="anLi hasBeenAnswer" data-type=" ' + item.type + '"  data-index="' + (parseInt(an.length + am.length + ab.length + index)) + '" data-id="' + item.id + '"><a href="#">' + (parseInt(an.length + am.length + ab.length + index) + 1) + '</a></li>';
        })

        $("#case").html(str)  //答题卡
        $('.case-num').html($("#case").find('li').length)
        if ($("#case").find('li').length <= 0) {
            $('.anlifenxi').hide()
            $('.exam-name').addClass('anliClass')
        }
        str = '';
        ab.map(function (item, index) {
            str += '<li class="anLi" data-type=" ' + item.type + '"  data-index="' + (parseInt(an.length + am.length + index)) + '" data-id="' + item.id + '"><a href="#">' + (parseInt(an.length + am.length + index) + 1) + '</a></li>';
        })
        $("#questionsBox").html(str)  //答题卡
        $('.questionsBox-num').html($("#questionsBox").find('li').length)

        // rich();

    }

    function toGo(index) {
        changeCss(index)
    }

    function first() {
        index = 0;
        $(".gray").css('background', '#ccc').attr('disabled', true);
        $(".green").css('background', '#43BD00').attr('disabled', false);

        if ($('.titleEaxm').eq(index).attr('type') == "1") {
            $(".subjectType").text('多项选择题');
            $(".tap").find('dd').eq(1).addClass('active').siblings().removeClass('active');
        } else {
            $(".subjectType").text('单项选择题');
            $(".tap").find('dd').eq(0).addClass('active').siblings().removeClass('active');
        }

        if ($('.titleEaxm').eq(index).attr('type') == "4") {
            $(".subjectType").text('案例分析题部分');
        }

        changeCss(index)
    }

    function last() {
        index = exam.questions.length - 1;
        $(".gray").css('background', '#43BD00').attr('disabled', false);
        $(".green").css('background', '#ccc').attr('disabled', true);

        if ($('.titleEaxm').eq(index).attr('type') == "1") {
            $(".subjectType").text('多项选择题');
            $(".tap").find('dd').eq(1).addClass('active').siblings().removeClass('active');
        } else {
            $(".subjectType").text('单项选择题');
            $(".tap").find('dd').eq(0).addClass('active').siblings().removeClass('active');
        }
        if ($('.titleEaxm').eq(index).attr('type') == "4") {
            $(".subjectType").text('案例分析题部分');
        }

        changeCss(index)
    }

    function next() {
        index = parseInt(index) + parseInt(1);

        if (index > 0) {
            $(".gray").css('background', '#43BD00').attr('disabled', false);
        }
        if (index + 1 >= exam.questions.length) {
            $(".green").css('background', '#ccc').attr('disabled', true);
            index = exam.questions.length - 1;
            console.log('haha2', index)
        } else {
            $(".green").css('background', '#43BD00');
        }

        if ($('.titleEaxm').eq(index).attr('type') == "1") {
            $(".subjectType").text('多项选择题');
            $(".tap").find('dd').eq(1).addClass('active').siblings().removeClass('active');
        } else {
            $(".subjectType").text('单项选择题');
            $(".tap").find('dd').eq(0).addClass('active').siblings().removeClass('active');
        }
        if ($('.titleEaxm').eq(index).attr('type') == "4") {
            $(".subjectType").text('案例分析题部分');
        }

        if ($('.titleEaxm').eq(index).attr('type') == 2) {
            $(".subjectType").text('判断题');
        }

        changeCss(index)
    }

    function pre() {
        index = parseInt(index) - parseInt(1);

        if (index < exam.questions.length) {
            $(".green").css('background', '#43BD00').attr('disabled', false);
        }
        if (index <= 0) {
            $(".gray").css('background', '#ccc').attr('disabled', true);
            index = 0;
        } else {
            $(".gray").css('background', '#43BD00');
        }

        if ($('.titleEaxm').eq(index).attr('type') == "1") {
            $(".subjectType").text('多项选择题');
            $(".tap").find('dd').eq(1).addClass('active').siblings().removeClass('active');
        } else {
            $(".subjectType").text('单项选择题');
            $(".tap").find('dd').eq(0).addClass('active').siblings().removeClass('active');
        }

        if ($('.titleEaxm').eq(index).attr('type') == 2) {
            $(".subjectType").text('判断题');
        }

        changeCss(index)
        // rich()
    }

    //刷新考试结束时间
    function reload() {
        console.log('请求接口')
        $.ajax({
            url: "/jzweb/exceptionAddtime/delayed",
            data: {
                stuId: JSON.parse(window.localStorage.getItem("info")).stuSignId,
                eBatchId: JSON.parse(window.localStorage.getItem("intro")).id
            },
            success: function (r) {
                let info = JSON.parse(window.localStorage.getItem("info"));
                info.endDate = r.data.endTime;
                window.localStorage.setItem('isTrue', JSON.stringify(r.data.isTrue));
                window.localStorage.setItem("endTime", r.data.endTime);
                window.localStorage.setItem("info", JSON.stringify(info));
                oneReload=true
                console.log('接口成功',oneReload)
            }
        });
    }

    //控制题目展示
    function changeCss(index) {
        $('.box').each(function (i, res) {
            if (index == i) {
                $(this).addClass("contentBoxShow");
                $(this).removeClass("contentBoxHide");
            } else {
                $(this).addClass("contentBoxHide");
                $(this).removeClass("contentBoxShow")
            }
        });

    }

    //提交答卷
    function submit() {

        // var t = Math.round(Math.random());
        //0-9随机数
        var t = Math.floor(Math.random() * 10);
        //console.log("answerList", JSON.stringify(answerList));
        // var answerList = JSON.parse(window.localStorage.getItem("answerList"));
        var answerList = window.localStorage.getItem("answerList");
        var textBox = window.localStorage.getItem("textBox");
        var tolBox = [];
        var examBatchId;
        var id = layer.msg('提交中，请等待！', {
            icon: 16,
            shade: 0.4,
            time: false //取消自动关闭
        });

        if (!answerList) {
            answerList = [];
            $('.titleEaxm').each(function (i, res) {
                answerList.push({id: $(res).attr('data-id'), value: '', type: $(res).attr("type")});
            })
            answerList = JSON.stringify(answerList);
        }

        tolBox.push({
            id: '',
            value: '',
            type: 4
        });

        // tolBox = JSON.stringify(tolBox);

        // if (!textBox) {
        //     textBox = [];
        //     $('.titleEaxm').each(function (i, res) {
        //         textBox.push({id: $(res).attr('data-id'), value: '', type: $(res).attr("type")});
        //     })
        //     textBox = JSON.stringify(textBox);
        // }

        answerList = JSON.parse(answerList);
        // textBox = JSON.parse(textBox);

        tolBox = [...answerList, ...tolBox];

        tolBox = JSON.stringify(tolBox);

        // type ==1  现在的题目(应用分析题)
        // type ==2  理论题

        setTimeout(function () {
            $.ajax({
                type: "POST",
                url: "/jzApi/examinations/selAnswerSheet",
                data: {
                    stuSignId: info.stuSignId,
                    epaperId: exam.id,
                    answerList: tolBox,
                    code: info.cookieCode,
                    file: $(".btnUploadimgtext").attr('title') ?? ''
                    // type: '4'
                },
                success: function (r) {
                    //console.log("r",r)
                    window.removeEventListener('beforeunload', resizeWindow, false);
                    if (r.code == 0) {
                        //提交试卷后清除缓存
                        var name = info.name
                        var ticketNumber = info.ticketNumber
                        var idNumber = info.idCard
                        localStorage.removeItem("info");
                        localStorage.removeItem("exam");
                        localStorage.removeItem("intro");
                        localStorage.removeItem("answerList");
                        localStorage.removeItem("endTime");
                        localStorage.removeItem("dates");
                        localStorage.removeItem("incomplete");
                        localStorage.removeItem("times");
                        localStorage.removeItem("endTimes");
                        localStorage.removeItem("textBox");
                        localStorage.clear();
                        location.href = '/examination/endExam?name=' + name + '&ticketNumber=' + ticketNumber + '&idNumber=' + idNumber;
                    } else {
                        layer.msg(r.msg);
                        location.href = '/examination/endExam?name=' + name + '&ticketNumber=' + ticketNumber + '&idNumber=' + idNumber;
                    }
                }
            });
        }, 2000);
    }
</script>
</body>





